package com.khadi.testcase.view.model;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

public class ProcessTableModel extends AbstractTableModel {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3254862419782917745L;

	private String[] columns;
	private List<ProcessModel> data;

	public ProcessTableModel(String[] columns) {
		this.columns = columns;
	}

	@Override
	public String getColumnName(int column) {

		return this.columns[column];
	}

	@Override
	public int getColumnCount() {
		// TODO Auto-generated method stub
		return this.columns.length;
	}

	@Override
	public int getRowCount() {
		// TODO Auto-generated method stub
		return getData().size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		ProcessModel processModel = getValueAt(rowIndex);
		switch (columnIndex) {
		case 0:
			return processModel.getWorkFlowName();
		case 1:
			return processModel.getWaitingTime();
		case 2:
			return processModel.getSequence();
		default:
			return null;
		}
	}

	@Override
	public void setValueAt(Object value, int rowIndex, int columnIndex) {
		ProcessModel processModel = getValueAt(rowIndex);
		switch (columnIndex) {
		case 1:
			if (value != null) {
				processModel.setWaitingTime((Integer) value);
			} else {
				processModel.setWaitingTime(null);
			}
			break;
		case 2:
			if (value != null) {
				processModel.setSequence((Integer) value);
			} else {
				processModel.setSequence(null);
			}
			break;
		}
	}

	@Override
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		// TODO Auto-generated method stub
		return true;
	}

	public ProcessModel getValueAt(int rowIndex) {

		return getData().get(rowIndex);
	}

	public void setData(List<ProcessModel> data) {
		this.data = data;
	}

	public List<ProcessModel> getData() {
		if (this.data == null) {
			this.data = new ArrayList<ProcessModel>();
		}
		return data;
	}
}
